// 二维码生成前端调用demo

var  express = require('express');
var app = express();
var qr = require('qr-image');
// 解决跨域
app.all('/',(req,res,next)=>{
    res.setHeader('Access-Control-Allow-Origin', '*');
    res.setHeader('Access-Control-Allow-Methods', 'GET, POST');
    res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type, Authorization');
    next();
});

app.post('/Code',(req,res)=>{
    let text = 'https://www.baidu.com';
    let svg_string = qr.imageSync(text, { type: 'svg' });
    res.send(svg_string);
})

var server = app.listen(3000,()=>{
    var host = server.address().address
    var port = server.address().port
    console.log('成功监听',host,port);
})